package com.gg.user.gguser.dao;


import com.gg.user.gguser.dataobject.GgUserDataobject;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GgUserDaoMapper {
    @Select("select count(*) from gg_user")
    Integer getUserSelectCount(); //获取全部信息
    //Integer getUserSelectCount(@Param("role")Integer role, @Param("id")Integer id);

    @Select("select count(*) from gg_user where gg_username = #{username}")
    Integer getUserNameSelectCount(@Param("username")String username); //获取用户名知否存在

    @Select("select gg_id as ggId,gg_username as ggUsername,gg_password as ggPassword,gg_nicheng as ggNicheng, gg_dengji as ggDengji,gg_charutime as ggCharutime,gg_updatetime as ggUpdatetime,gg_neiwai as ggNeiwai,gg_logo as ggLogo,gg_youxiang as ggYouxiang,gg_phone as ggPhone,gg_token as token,gg_status as ggStatus from gg_user where gg_username = #{username}")
    GgUserDataobject getUserNameSelect(@Param("username")String username); //获取用户名获取用户信息

    @Select("select gg_id as ggId, gg_username as ggUsername,gg_nicheng as ggNicheng, gg_charutime as ggCharutime,gg_updatetime as ggUpdatetime,gg_neiwai as ggNeiwai,gg_logo as ggLogo,gg_youxiang as ggYouxiang,gg_grade as ggGrade,gg_phone as ggPhone from gg_user where gg_username = #{username}")
    GgUserDataobject getUserNameSelectQ(@Param("username")String username);//获取可以让前台看到的用户信息

    // 注册用户
    @Insert("insert into gg_user(gg_id, gg_username, gg_password, gg_youxiang, gg_phone, gg_nicheng, gg_token,gg_grade) values (REPLACE(UUID(),\"-\",\"\"),#{username}, #{password}, #{youxiang}, #{phone}, #{nicheng}, #{token}, #{ggGrade})")
    Integer installName(@Param("username")String username,@Param("password")String password,@Param("nicheng")String nicheng,@Param("youxiang")String youxiang,@Param("phone")String phone,@Param("token")String token,@Param("ggGrade")Integer ggGrade);

    // 游客身份修改
    @Update("update gg_user set gg_grade=#{ggGrade} where gg_id=#{ggId}")
    Integer updateUserRole(@Param("ggGrade")Integer ggGrade, @Param("ggId")String ggId);

    @Select({
            "<script>",
                "select count(*) from gg_user where gg_id != '1'",
                "<if test='ggGrade!=null and ggGrade!=\"\"'>",
                    "and gg_grade = #{ggGrade}",
                "</if>",
            "</script>"
    })
    Integer getRootUserSelectCountGrade(@Param("ggGrade")Integer ggGrade); // 获取全部信息

    // 获取用户信息
    @Select({
            "<script>",
                "select gg_id as ggId,gg_username as ggUsername,gg_password as ggPassword,gg_nicheng as ggNicheng, gg_grade as ggGrade,date_format(gg_charutime, '%Y-%m-%d %H:%i:%s') as ggCharutime,date_format(gg_updatetime, '%Y-%m-%d %h:%m:%s') as ggUpdatetime,gg_neiwai as ggNeiwai,gg_logo as ggLogo,gg_youxiang as ggYouxiang,gg_phone as ggPhone,gg_token as token,gg_status as ggStatus from gg_user  where gg_id != '1'",
                "<if test='ggGrade!=null and ggGrade!=\"\"'>",
                    "and gg_grade = #{ggGrade}",
                "</if>",
            "order by gg_updatetime desc limit #{page},#{pageNumber}"
            , "</script>"
    })
    List<GgUserDataobject> getRootUserSelectCount(@Param("page")Integer page, @Param("pageNumber")Integer pageNumber,@Param("ggGrade")Integer ggGrade);

    @Select("select count(*) from gg_binding gb left join gg_user gu on gb.gg_b_b_user_id = gu.gg_id where gb.gg_b_d_user_id=#{ggUserId}")
    Integer getGgBinDing(@Param("ggUserId")String ggUserId);// 获取全部公司下面绑定的用户

    @Select("select gg_id as ggId,gg_username as ggUsername,gg_password as ggPassword,gg_nicheng as ggNicheng, gg_grade as ggGrade,date_format(gg_charutime, '%Y-%m-%d %H:%i:%s') as ggCharutime,date_format(gg_updatetime, '%Y-%m-%d %h:%m:%s') as ggUpdatetime,gg_neiwai as ggNeiwai,gg_logo as ggLogo,gg_youxiang as ggYouxiang,gg_phone as ggPhone,gg_token as token,gg_status as ggStatus from gg_binding gb left join gg_user gu on gb.gg_b_b_user_id = gu.gg_id where gb.gg_b_d_user_id=#{ggUserId}")
    List<GgUserDataobject> getGgBinDingSelectCount(@Param("page")Integer page, @Param("pageNumber")Integer pageNumber,@Param("ggUserId")String ggUserId);// 获取全部公司下面绑定的用户

    //修改状态
    @Update("update gg_user set gg_status=#{status} where gg_id=#{ggId}")
    Integer setStatus(@Param("status")Integer status,@Param("ggId")String ggId);

    // 修改密码
    @Update("update gg_user set gg_password=#{userPassWord} where gg_id=#{userId}")
    Integer updatePassWord(@Param("userId")String userId,@Param("userPassWord")String userPassWord);

    // 修改头像
    @Update("update gg_user set gg_logo=#{url} where gg_id=#{userId}")
    Integer updatLogo(@Param("userId")String userId,@Param("url")String url);

    // 修改昵称
    @Update("update gg_user set gg_nicheng=#{nicheng} where gg_id=#{userId}")
    Integer updatNiCheng(@Param("userId")String userId,@Param("nicheng")String nicheng);

    //修改绑定手机号
    @Update("update gg_user set gg_phone=#{phone} where gg_id=#{userId}")
    Integer updatPhone(@Param("userId")String userId,@Param("phone")String phone);

    // 修改绑定邮箱
    @Update("update gg_user set gg_youxiang=#{youxiang} where gg_id=#{userId}")
    Integer updatYouXiang(@Param("userId")String userId,@Param("youxiang")String youxiang);
}
